package com.kuang.demo.service.wx;

import com.kuang.demo.bo.zzywx.user.MyOrder;
import com.kuang.demo.bo.zzywx.user.OrderStatus;
import com.kuang.demo.mapper.wx.WXUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WXUserServiceImpl implements WXUserService {
    @Autowired
    WXUserMapper wxUserMapper;

    @Override
    public MyOrder selectAllOrder(String name) {
        //首先从数据库中根据username取到对应的user_id;
        int userId = wxUserMapper.selectUserIdByName(name);

        List<OrderStatus> orderStatuses = wxUserMapper.selectAllOrder(userId);


        MyOrder order = new MyOrder();

        for (OrderStatus orderStatus : orderStatuses) {
            if(orderStatus.getOrderStatus() == 101){
                order.setUnpaid(orderStatus.getNum());
            }else if(orderStatus.getOrderStatus() == 201){
                order.setUnship(orderStatus.getNum());
            }else if(orderStatus.getOrderStatus() == 301){
                order.setUnrecv(orderStatus.getNum());
            }else if(orderStatus.getOrderStatus() == 401){
                order.setUncomment(orderStatus.getNum());
            }
        }

        return order;
    }
}
